<?php
namespace app\common\model;
use think\Db;
use think\Model;
class Projectitem extends Model{
    //获取当前打卡信息
    public function getItem(){

        $where=[
            'uid'=>cookie('uid'),
            'status'=>0,
            'count_status'=>0,
            'signbegin_time' => ['gt',time()]
        ];
        $res=$this->where($where)->find();
        return $res;
    }
    //获取今天所有人打卡记录
    public function getToDayItem(){
//        应该在昨天和今天之中
//        2018年7月14日18:23:27 修改
        $yday = strtotime(date('Y-m-d',strtotime('-1 days')). "23:59");
        $toDay=strtotime(date('Y-m-d').'23:59');
//        echo date('Y-m-d H:i:s','1531391442');die;
        $where=[
//            'signbegin_time'=>['lt',$toDay],
            'signbegin_time'=>['between',"$yday,$toDay"],
            'count_status'=>0,
        ];
        $res=Db::table('zq_projectitem')->where($where)->order('create_time','desc')->select();
        return $res;
    }

    /**
     * 获取6点30之前和之后的 参加打卡项目记录
     */
    public function getdayItem(){
       $begin_time = strtotime(date('Y-m-d') . "6:30");
        if(time()<$begin_time){
                $res = $this->getToDayItem();
        }
        if(time()>=$begin_time){
                $where = [
                    'create_time' => ['gt',$begin_time],
                    'count_status' => 0
                ];
               $res = $this->where($where)->order('create_time','desc')->select();
        }
        return $res;
    }

    //获取所有已打卡记录
    public function getAllSigned(){
        $where=[
            'status'=>1
        ];
        $res=$this->where($where)->select();
        return $res;
    }

    //获取当月打卡记录
    public function getToMoney($year,$month){
        $curYear=$year;//开始年份
        $curMonth=$month;//开始月份
         $month_days=cal_days_in_month(CAL_GREGORIAN, $curMonth, $curYear);//当月天数
        $begin=$curYear.'-'.$curMonth.'-1 00:00';//开始时间
        $end=$curYear.'-'.$curMonth.'-'.$month_days.' 23:59';//结束时间
        $begin= strtotime($begin);
        $end=strtotime($end);
       /* print_r($begin);
        echo'\\';
        print_r($end);exit;*/
        $where=[
            'signbegin_time'=>  array(['gt',$begin],['lt',$end],'and'),
            "uid" => cookie('uid')
        ];
        $res=$this->where($where)->select();
        return $res;
    }


}